<?php
namespace app\admin\controller;
use app\admin\controller\AdminBaseController;
use think\Cache;
use think\Db;

/**
 * 异常
 */
class TraceController extends BaseController {
		
	public function feedback($user_name='',$status=''){
		$where=[];
		if($user_name){
			$where['user_name']=array("like","%".$user_name."%");
		}
		$this->assign('user_name',$user_name);
		if($status){
			$where['status']=$status;
		}
		$this->assign('status',$status);
		
		$list=db('sys_feedback')->order("msg_time desc")->where($where)->paginate(15);
		$this->assign('list',$list);
		return $this->fetch();
	}
	public function sh_feedback(){
		$tx=db('sys_feedback')->where("id",input("id"))->find();
		$this->assign('tx',$tx);
		return $this->fetch();
	}
	//会员异常账号
	public function m_danger($mobile='',$user_name=''){
		$where=[];
		if(input("mobile")){
			$where['a.mobile']=array('like',"%".input('mobile')."%");
		}
		$this->assign('mobile',$mobile);
		if(input("user_name")){
			$where['a.user_name']=array('like',"%".input('user_name')."%");
		}
		$this->assign('user_name',$user_name);
		$sql=db('member_charge')->field("sum(balance) balance,user_id")->group("user_id")->buildSql();
		$list=db("member")->alias("a")->join($sql." b","b.user_id=a.user_id")->field("a.*,b.balance")->where("b.balance !=a.money")
		->where($where)->paginate(15, false, get_query());
		$this->assign('list',$list);
		return $this->fetch();
	}
	//会员消费异常账号
	public function m_xfdanger($mobile='',$user_name=''){
		$where=[];
		if(input("mobile")){
			$where['a.mobile']=array('like',"%".input('mobile')."%");
		}
		$this->assign('mobile',$mobile);
		if(input("user_name")){
			$where['a.user_name']=array('like',"%".input('user_name')."%");
		}
		$this->assign('user_name',$user_name);
		$sql=db('member_score')->field("sum(balance) balance,user_id")->group("user_id")->buildSql();
		$list=db("member")->alias("a")->join($sql." b","b.user_id=a.user_id")->field("a.*,b.balance")->where("b.balance !=a.score")
		->where($where)->paginate(15, false, get_query());
		$this->assign('list',$list);
		return $this->fetch();
	}
	//商家余额异常账号
	public function a_danger($mobile='',$agent_name=''){
		$where=[];
		if(input("mobile")){
			$where['a.mobile']=array('like',"%".input('mobile')."%");
		}
		$this->assign('mobile',$mobile);
		if(input("agent_name")){
			$where['a.agent_name']=array('like',"%".input('agent_name')."%");
		}
		$this->assign('agent_name',$agent_name);
		
		$sql=db('agent_charge')->field("sum(balance) balance1,agent_id")->group("agent_id")->buildSql();
		$list=db("agent")->alias("a")->join($sql." b","b.agent_id=a.id")->field("a.*,b.balance1")->where("b.balance1 !=a.balance")->where($where)->paginate(15, false, get_query());
		$this->assign('list',$list);
		return $this->fetch();
	}
	
	

}
